<template>
  <div>
    <h1>修改密码</h1>
    <br>
    <span>请输入旧密码</span>
    <el-input type="text" v-model="oldPassword" style="width: 10%"></el-input>
    <br><br>
    <span>请输入新密码</span>
    <el-input type="text" v-model="newPassword" style="width: 10%"></el-input>
    <br><br>
    <span>请确认新密码</span>
    <el-input type="text" v-model="nowPassword" style="width: 10%"></el-input>
    <br><br>
    <el-button type="primary" @click="updatePassword()">修改</el-button>
    <br><br>

  </div>
</template>

<script>
import axios from "axios";
import {ElMessage} from "element-plus";

export default {
  name: "ChangePassword",
  created() {

  },
  data() {
    return {
      oldPassword: '',
      newPassword: '',
      nowPassword: ''

    }

  }, methods: {
    updatePassword() {
      if (this.nowPassword == this.newPassword) {
        let param = new URLSearchParams
        param.append("oldPassword", this.oldPassword)
        param.append("nowPassword", this.nowPassword)


        axios.post("/api/user/updatePassword", param).then(res => {
          if (res.data == "ok") {
            ElMessage({
              message: '修改成功',
              type: 'success'
            })
            this.oldPassword = '';
            this.newPassword = '';
            this.nowPassword = ''
          } else {
            ElMessage({
              message: '旧密码错误',
              type: 'success'
            })
          }
        })
      } else {
        ElMessage({
          message: '两次密码不一致',
          type: 'success'
        })
      }
    }
  }
}
</script>

<style scoped>

</style>